/////////////////////////////////////////////////////////////////////////////
// Name:        ax_view_summary.cpp
// Purpose:     Summary view
// Author:      Julian Smart
// Modified by:
// Created:     2009-03-20
// RCS-ID:
// Copyright:   (c) Julian Smart
// Licence:     New BSD License
/////////////////////////////////////////////////////////////////////////////

#include "wx/wx.h"

#include "ax/ax_pagerctrl.h"
#include "ax/ax_view_summary.h"
#include "ax/ax_summaryviewpanel.h"

/*
 * AxSummaryView implementation
 * Handles summary UI
 */

IMPLEMENT_DYNAMIC_CLASS( AxSummaryView, AxView )

void AxSummaryView::Init()
{
}

bool AxSummaryView::Activate(AxViewManager* viewManager, AxDocument* doc)
{
    // In case the window hasn't been created yet
    Initialize(viewManager);

    AssociateDocument(doc);

    AxSummaryViewPanel* panel = GetSummaryViewPanel();
    if (panel)
    {
        ShowWindow(viewManager);
    }

    return true;
}

bool AxSummaryView::Deactivate(AxViewManager* WXUNUSED(viewManager))
{
    return true;
}

bool AxSummaryView::Initialize(AxViewManager* viewManager)
{
    if (!GetWindow())
    {
        AxSummaryViewPanel* panel = wxDynamicCast(viewManager->GetViewPagerCtrl()->FindPageWindow(wxT("Summary")), AxSummaryViewPanel);
        if (!panel)
        {
            panel = new AxSummaryViewPanel(viewManager->GetViewPagerCtrl(), wxID_ANY);
            viewManager->GetViewPagerCtrl()->AddPage(panel, wxT("Summary"));
        }
        SetWindow(panel);
    }
    return true;
}

bool AxSummaryView::Uninitialize(AxViewManager* WXUNUSED(viewManager))
{
    return true;
}

AxSummaryViewPanel* AxSummaryView::GetSummaryViewPanel() const
{
    return wxDynamicCast(GetWindow(), AxSummaryViewPanel);
}

void AxSummaryView::SetDescription(const wxString& text)
{
    AxSummaryViewPanel* panel = GetSummaryViewPanel();
    if (panel)
    {
        panel->m_textCtrl->SetValue(text);
    }
}

